import request from '../../../components/Request';

export default {
  state: {
    count: 0,
    info: 'info',
    result: {code: 0}
  },
  reducers: {
    increment: (state, payload) => {
      console.log('state', state)
      return { ...state, count: state.count + 1, result: payload.result };
    },
    decrement: function(state, payload) {
      return { ...state, count: state.count - 1 };
    },
    show: function(state, action) {
      return { ...state, info: '我增加了' };
    }
  },
  effects: {
    increment: async ({state, payload}, {put, call}) => {
      // console.log("effects increment")

      let result = await request.post({ url: 'http://localhost:8000/public/listCfg.do' });
      put({type: 'increment', payload: {result}})
    },
    decrement: async function({state, payload}, {put, call}) {
      let result = await request.post({ url: 'http://localhost:8000/public/listCfg.do' });
      put({type: 'decrement', payload: {result}})
    },
    show: function({state, payload}, {put, call}) {
      console.log(payload);
    },

  },
  autorun: async  function({state}, {put, call}) {
    await call({ type: 'increment', payload: {}, loadingName: 'table_loading' })
     await call({ type: 'decrement', payload: {}, loadingName: 'table_loading' })
  }
};
